package com.margo.project.redis.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class RedisListOperationsServiceImpl<T> {
	@Autowired
	protected RedisTemplate<String, Object> redisTemplate;
	@Autowired
	protected ListOperations<String, Object> lstOperations;
	
	private static final String REDIS_KEY = "REDIS_LIST_KEY";
	
	protected String getRedisKey() {
		return RedisListOperationsServiceImpl.REDIS_KEY;
	}
	
	public void add(T t) {
		lstOperations.leftPush(getRedisKey(), t);
	}
	
	public List<Object> read() {
		return lstOperations.range(getRedisKey(), 0, lstOperations.size(getRedisKey()));
	}
	
	
	public Object pop() {
		return lstOperations.rightPop(getRedisKey());
	}
}
